package com.future.bantang.adapter;

import android.content.Context;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

import com.future.bantang.R;
import com.future.bantang.app.BanTangAPP;
import com.future.bantang.entity.SquareEntity;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by liufujie on 16-1-13.
 */
public class GrowGrassAdapter extends AbsBaseAdapter
        <SquareEntity.DataEntity.RecGroupsEntity> {

    //TODO 完成后删除
    private static final String TAG = "GrowGrassAdapter";

    public GrowGrassAdapter(Context context) {
        super(context, R.layout.square_grow_grass_lauout);
    }

    /**
     * 配置布局
     *
     * @param viewHolder
     * @param data
     */
    @Override
    public void bindDatas(ViewHolder viewHolder, SquareEntity.DataEntity.RecGroupsEntity data) {

        //设置背景图片
        ImageView ivBg = (ImageView) viewHolder.getView(R.id.iv_grow_grass_bg);
        BanTangAPP.getApp().getImageLoader().displayImage(data.getPic2(), ivBg);

        //设置标题
        ImageView ivTitle = (ImageView) viewHolder.getView(R.id.iv_grow_grass_title);
        BanTangAPP.getApp().getImageLoader().displayImage(data.getPic3(), ivTitle);

        TextView tvPeople = (TextView) viewHolder.getView(R.id.tv_grow_grass_views);
        tvPeople.setText(String.valueOf(data.getDynamic().getViews()));

        TextView tvPosts = (TextView) viewHolder.getView(R.id.tv_grow_grass_posts);
        tvPosts.setText(String.valueOf(data.getDynamic().getPosts()));
    }

    /**
     * 循环移动list下标位置
     *
     * @param list
     * @param distance
     */
    public void ListRotate(List list, int distance) {
        Collections.rotate(list, distance);
        this.notifyDataSetChanged();
    }

    /**
     * 设置数据
     *
     * @param list
     */
    @Override
    public void setDatas(List list) {
        this.mList.clear();
        this.mList = list;
        this.notifyDataSetChanged();
    }

    /**
     * 添加数据
     *
     * @param list
     */
    @Override
    public void addDatas(List list) {
        this.mList.addAll(list);
        this.notifyDataSetChanged();
    }

    /**
     * 清理数据
     */
    @Override
    public void clearDatas() {
        this.mList.clear();
    }
}
